package com.bruce.pattern.creational.builder;

import com.bruce.util.JsonUtils;
import org.junit.Test;

/**
 * Created by bruce on 2018/11/2 21:05
 */
public class MainTest {

    @Test
    public void test1() {
        CourseAbstractBuilder builder = new CourseBuilder();
        Coach coach = new Coach();
        coach.setBuilder(builder);
        Course course = coach.makeCourse("Java设计模式", "ppt",
                "video", "article", "问答");
        System.out.println(JsonUtils.toJson(course));
    }

    @Test
    public void test2() {
        Course.CourseBuilder courseBuilder = new Course.CourseBuilder();
        Course course = courseBuilder.courseName("Java设计模式")
                .coursePPT("ppt")
                .courseVideo("video")
                //.courseArticle("article")
                .courseQA("问答")
                .build();

        System.out.println(JsonUtils.toJson(course));
    }

    //使用@lombok.Builder() 注解可以直接生成 静态内部类构建类,类似于test2
    //但是@lombok.Builder()注解会生成带有所有参数的构造函数的class,并没有生产无参数构造函数,导致无法使用无参构造函数
    //可以配合@AllArgsConstructor 和 @NoArgsConstructor 两个注解同时使用
    @Test
    public void test3() {
        Course2.Course2Builder builder = Course2.builder();
        Course2 course2 = builder.courseName("Java设计模式")
                .coursePPT("ppt")
                .courseVideo("video")
                //.courseArticle("article")
                .courseQA("问答")
                .build();
        System.out.println(JsonUtils.toJson(course2));

        Course2 course21 = new Course2();



    }


}
